<?php
include_once($config['webroot']."/module/product/includes/plugin_pro_class.php");
include_once($config['webroot'].'/lib/phpqrcode/phpqrcode.php');
$id=$_GET["sid"]*1;
$id=$_GET["id"]*1;

$data = $config['weburl'].'/'.$_SERVER['REQUEST_URI'];
$filename = $config['webroot'].'/uploadfile/qrcode/'.$id.'.png';  //  生成的文件名
$errorCorrectionLevel = 'L';  // 纠错级别：L、M、Q、H
$matrixPointSize = 4; // 点的大小：1到10
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);


if($sid)
{
	$sql="select pid from ".SETMEAL." where id='$sid'";
	$db->query($sql);
	$id=$db->fetchField('pid');
}
$prodetail=new pro();
$prode=$prodetail->detail($id);
$osql = "select price from ".SETMEAL." where pid = '{$prode['pid']}' ";
$db->query($osql);
$o_list = $db->getRows();
$o_list = array_unique(array_column($o_list,'price'));
$max =array_search(max($o_list),$o_list);
$min =array_search(min($o_list),$o_list);
$prode['price_list'] = $o_list[$min].'-'.$o_list[$max];
if(!empty($prode['promotion_tips'])){
	$prode['promotion_list'] = explode(",",$prode['promotion_tips']);
}
$p_sql = "select performance_start_time,performance_end_time,id from ".SETMEAL." where pid = '{$prode['pid']}' ";
$db->query($p_sql);
$pers= $db->getRows();

$pers_date = array_unique(array_column($pers,'performance_start_time'));
$price_sql = "select price,price_desc,stock from ".SETMEAL." where pid = '{$prode['pid']}' and performance_start_time = '{$prode['performance_start_time']}' ";
$db->query($price_sql);
$price= $db->getRows();

$tpl->assign("price",$price);
$weekarray=array("日","一","二","三","四","五","六");
foreach($pers_date as $key => $val){

	$pers_dates[$val] = date("Y-m-d",$val).' 周'.$weekarray[date('w',$val)].' '.date("H:i:s",$val);

}

$tpl->assign("pers_date",$pers_dates);
$tpl->assign("calendar",$pers_date);

//-----------------------------------------
$sql="select isbuy,ext_table,brand from ".PCAT." where catid='$prode[catid]'";
$db->query($sql);
$current_cat=$db->fetchRow();

if($current_cat['isbuy']==1)
	$prode['isbuy']=1;
else
	$prode['isbuy']=0;
if($current_cat['brand'])
{
	$sql="select id,name from ".BRAND." where id in ($current_cat[brand]) limit 0 ,10 ";
	$db->query($sql);
	$brand=$db->getRows();
	$tpl->assign("brand",$brand);	
}

if(strlen($prode['catid'])>4)
{
	if(strlen($prode['catid'])>8)
		$catname[]=substr($prode['catid'],0,-6);
	if(strlen($prode['catid'])>6)
		$catname[]=substr($prode['catid'],0,-4);
	if(strlen($prode['catid'])>4)
		$catname[]=$parcat=substr($prode['catid'],0,-2);
	
	$catname[]=$prode['catid'];
	$tpl->assign("catname",$catname);
	
	$sql="select catid,cat from ".PCAT." where catid < '".$parcat."99' and catid > '".$parcat."00'";
	$db->query($sql);
	$cat=$db->getRows();	
	$tpl->assign("cat",$cat);
}
//-----------------------------------扩展字段
include_once("$config[webroot]/module/product/includes/plugin_add_field_class.php");
$addfield = new AddField('product');
$prode['extfiled']=$addfield->addfieldinput($prode['pid'],$current_cat['ext_table'],$prode['id']);

//场馆信息
if(!empty($prode['spot'])){
	$sql = "select * from ".SPOT." where id = '{$prode['spot']}' ";
	$db->query($sql);
	$prode['spot_detail'] = $db->fetchRow();

}

//答疑列表
$qsql = "select * from ".QUESTION." where product_id = '{$prode['pid']}' ";
$db->query($qsql);
$question_list = $db->getRows();
$tpl->assign("question_list",$question_list);

//=================送花显示=======================
$fsql= "select * from ".FLOWER." where uid = '$buid' and pid = '{$prode['pid']}'  ";
$db->query($fsql);
$is_flower = $db->getRows();
$tpl->assign("is_flower",$is_flower);
//============================购买说明 付款方式 ===温馨提示==========================
$buy_sql = "select * from ".WEBCON." where con_id = 9";
$db->query($buy_sql);
$buy_info = $db->fetchRow();
$fk_sql = "select * from ".WEBCON." where con_id = 11";
$db->query($fk_sql);
$fk_info = $db->fetchRow();
$tpl->assign("buy_info",$buy_info);
$tpl->assign("fk_info",$fk_info);

$wx_sql = "select * from ".WEBCON." where con_id = 21 ";
$db->query($wx_sql);
$wx_info = $db->fetchRow();

$tpl->assign("wx_info",$wx_info);
//var_dump(time());
//var_dump($prode['per_date_end']);
//exit;
//-----------------------------------咨询分类
$sql="select * from ".CONSULTCAT." order by id";
$db->query($sql);
$consultcat=$db->getRows();
$tpl->assign("consultcat",$consultcat);

//---------------------------------相关票品---------------------------
$x_sql="select s.*,p.pname from ".SETMEAL." s left join ".PRO." p on s.pid=p.id where s.stock >0 group by s.pid order by s.id  desc limit 0,5";
$db->query($x_sql);
$about_product = $db->getRows();
$tpl->assign('about_product',$about_product);

//-----------------------------------评价
$prode['count']=$prodetail->get_comment_count($id);
$prode['good']=$prodetail->get_comment($id,'1',$prode['count']);
$prode['middle']=$prodetail->get_comment($id,'0',$prode['count']);
$prode['bad']=$prodetail->get_comment($id,'-1',$prode['count']);


//-----------------------------------用户区获取
$prode['user_ip']=convertip(getip());
if($prode['user_ip']=='- LAN')
	$prode['user_ip']='';	
	
$prode['user_ip']=$prode['user_ip']?$prode['user_ip']:"上海";	
//$prode['freight_count']=get_log_price($prode['freight'],$prode['user_ip']);//跟据所在地自动算出的运费

$ar1=array('[catname]','[title]','[keyword]','[brand]');
$ar2=array($pcats['cat'],$prode['pname'],$prode['keywords'],$prode['brand']);
//$config['title']=str_replace($ar1,$ar2,$config['title3']);
$config['title'] = $prode['pname'];
$config['keyword']=str_replace($ar1,$ar2,$config['keyword3']);
$config['description']=str_replace($ar1,$ar2,$config['description3']);
//======================================

$tpl->assign("config",$config);
$tpl->assign("de",$prode);
$tpl->assign("current","product");
include_once("footer.php");
$out=tplfetch("product_detail.htm",$flag);

?>